home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / thesource6.dms / thesource6.adf / Source / Compression / hcompress.lha / hcompress / vms / modify.c < prev   
Encoding:
C/C++ Source or Header  |  1992-04-22  |  2.9 KB  |  111 lines

  1. /* modify.c   Modify RMS record header for VMS file to turn a stream format
  2.  *              file into a fixed-length blksiz-byte format files.
  3.  *
  4.  * Programmer: R. White     Date: 22 April 1992
  5.  */
  6. #include <stdio.h>
  7. #include <file.h>
  8.  
  9. static void modify();
  10.  
  11. static void
  12. usage()
  13. {
  14.     fprintf(stderr, "Usage: MODIFY filename [ blksize ]\n");
  15.     exit(-1);
  16. }
  17.  
  18. main (argc, argv)
  19. int argc;
  20. char *argv[];
  21. {
  22. int arg = 0;
  23. char *filename;
  24. int blksiz;
  25.  
  26.     if (++arg >= argc) usage();
  27.     filename = argv[arg];
  28.     if (++arg < argc) {
  29.         if (sscanf(argv[arg], "%d", &blksiz) != 1) {
  30.             fprintf(stderr, "modify: bad blksize %s\n", argv[arg]);
  31.             usage();
  32.         }
  33.     } else {
  34.         blksiz = 512;
  35.     }
  36.     if (++arg < argc) {
  37.         fprintf(stderr, "modify: too many parameters %s...\n", argv[arg]);
  38.         usage();
  39.     }
  40.     modify(filename, blksiz);
  41.     exit(0);
  42. }
  43.  
  44. /* Procedure which changes record format to fixed and record 
  45.  * length to blksiz (parameter) for file filename (parameter)
  46.  * by modifying file header.
  47.  *
  48.  * As written by C, the file has the following attributes:
  49.  *
  50.  *    Record format:      Stream_LF
  51.  *    Record attributes:  Carriage return carriage control
  52.  *
  53.  * After being modified, it has:
  54.  *
  55.  *    Record format:      Fixed length <blksiz> byte records
  56.  *    Record attributes:  None
  57.  *
  58.  * The binary contents of the file are just fine for fixed length records
  59.  * (i.e. there's no extra junk between records).  It's convenient to write
  60.  * the file in the default Stream_LF format, though, because then I don't
  61.  * have to break up all the records into <blksiz>-byte chunks.
  62.  *
  63.  * Created from a program from Pittsburgh Supercomputer Center.
  64.  *
  65.  * Programmer: R. White Date: 1 April 1988
  66.  */
  67.  
  68. #include <fab.h>
  69. #define RME$C_SETRFM    0X00000001
  70.  
  71. static void
  72. modify(filename, blksiz)
  73. char *filename;
  74. long blksiz;
  75. {
  76. struct FAB myfab = cc$rms_fab;
  77. long status;
  78.  
  79.     if (blksiz < 1 || blksiz > 32767) {
  80.         fprintf(stderr,
  81.             "modify: blocksize must be between 1 and 32767 inclusive.");
  82.         exit(1);
  83.     }
  84.  
  85.     myfab.fab$b_fac = FAB$M_PUT;        /* file access mode = put access */
  86.     myfab.fab$l_fop |= FAB$M_ESC;       /* escape to allow $modify */
  87.     myfab.fab$l_ctx |= RME$C_SETRFM;    /* user context (whatever that is) */
  88.     myfab.fab$w_ifi = 0;                /* internal file identifier */
  89.  
  90.     myfab.fab$l_fna = filename;         /* filename */
  91.     myfab.fab$b_fns = strlen(filename); /* filename length */
  92.  
  93.     if (((status = SYS$OPEN(&myfab, 0, 0)) & 7) != 1) {
  94.         fprintf(stderr,"modify: Couldn't open %s\n", filename);
  95.         exit(status);
  96.     }
  97.  
  98.     myfab.fab$w_mrs = blksiz;           /* record length */
  99.     myfab.fab$b_rfm = FAB$C_FIX;        /* fixed record format */
  100.  
  101.     if (((status = SYS$MODIFY(&myfab, 0, 0)) & 7) != 1) {
  102.         fprintf(stderr,"modify: Couldn't modify %s\n", filename);
  103.         exit(status);
  104.     }
  105.  
  106.     if (((status = SYS$CLOSE(&myfab, 0, 0)) & 7) != 1) {
  107.         fprintf(stderr,"modify: Couldn't close %s\n", filename);
  108.         exit(status);
  109.     }
  110. }
  111.